{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Count the Number of Consistent Strings"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #bit-manipulation #array #hash-table #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #位运算 #数组 #哈希表 #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: countConsistentStrings"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #统计一致字符串的数目"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个由不同字符组成的字符串 <code>allowed</code> 和一个字符串数组 <code>words</code> 。如果一个字符串的每一个字符都在 <code>allowed</code> 中，就称这个字符串是 <strong>一致字符串 </strong>。</p>\n",
    "\n",
    "<p>请你返回 <code>words</code> 数组中 <strong>一致字符串</strong> 的数目。</p>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<b>输入：</b>allowed = \"ab\", words = [\"ad\",\"bd\",\"aaab\",\"baa\",\"badab\"]\n",
    "<b>输出：</b>2\n",
    "<b>解释：</b>字符串 \"aaab\" 和 \"baa\" 都是一致字符串，因为它们只包含字符 'a' 和 'b' 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<b>输入：</b>allowed = \"abc\", words = [\"a\",\"b\",\"c\",\"ab\",\"ac\",\"bc\",\"abc\"]\n",
    "<b>输出：</b>7\n",
    "<b>解释：</b>所有字符串都是一致的。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<b>输入：</b>allowed = \"cad\", words = [\"cc\",\"acd\",\"b\",\"ba\",\"bac\",\"bad\",\"ac\",\"d\"]\n",
    "<b>输出：</b>4\n",
    "<b>解释：</b>字符串 \"cc\"，\"acd\"，\"ac\" 和 \"d\" 是一致字符串。\n",
    "</pre>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 <= words.length <= 10<sup>4</sup></code></li>\n",
    "\t<li><code>1 <= allowed.length <=<sup> </sup>26</code></li>\n",
    "\t<li><code>1 <= words[i].length <= 10</code></li>\n",
    "\t<li><code>allowed</code> 中的字符 <strong>互不相同</strong> 。</li>\n",
    "\t<li><code>words[i]</code> 和 <code>allowed</code> 只包含小写英文字母。</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [count-the-number-of-consistent-strings](https://leetcode.cn/problems/count-the-number-of-consistent-strings/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [count-the-number-of-consistent-strings](https://leetcode.cn/problems/count-the-number-of-consistent-strings/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"ab\"\\n[\"ad\",\"bd\",\"aaab\",\"baa\",\"badab\"]', '\"abc\"\\n[\"a\",\"b\",\"c\",\"ab\",\"ac\",\"bc\",\"abc\"]', '\"cad\"\\n[\"cc\",\"acd\",\"b\",\"ba\",\"bac\",\"bad\",\"ac\",\"d\"]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        for i in set(allowed):\n",
    "            for j in range(len(words)):\n",
    "                words[j] = words[j].replace(i, '')\n",
    "        return words.count('')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        steps = 0\n",
    "        for word in words:\n",
    "            flag = True\n",
    "            wordslist = list(word)\n",
    "            for i in wordslist:\n",
    "                if i not in allowed:\n",
    "                    flag = False\n",
    "            if flag:\n",
    "                steps += 1\n",
    "        return steps        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        mask = 0\n",
    "        for c in allowed:\n",
    "            mask |= 1 << (ord(c) - ord('a'))\n",
    "        res = 0\n",
    "        for word in words:\n",
    "            mask1 = 0\n",
    "            for c in word:\n",
    "                mask1 |= 1 << (ord(c) - ord('a'))\n",
    "            res += (mask1 | mask) == mask\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        count=0\n",
    "\n",
    "        for i in words:\n",
    "            for j in set(i):\n",
    "                if j not in allowed:\n",
    "                    break\n",
    "            else:\n",
    "                count+=1\n",
    "        return count        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        count = 0\n",
    "        for word in words:\n",
    "            if all(_ in allowed for _ in word):\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        res = 0\n",
    "        panduan = set(allowed)\n",
    "        for i in words:\n",
    "            if set([j for j in i]).issubset(panduan):\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        cnt = 0\n",
    "        for word in words:\n",
    "            for s in word:\n",
    "                if s not in allowed:\n",
    "                    fg = 0\n",
    "                    break\n",
    "            else: cnt += 1\n",
    "        return  cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        l = len(words)\n",
    "        sum = 0\n",
    "        for i in range(l):\n",
    "            s = words[i]\n",
    "            flag = 1\n",
    "            for j in s:\n",
    "                if j not in allowed:\n",
    "                    flag = 0\n",
    "            if flag == 1:\n",
    "                sum = sum + 1\n",
    "        return sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        cnt = 0\n",
    "        for word in words:\n",
    "            for s in word:\n",
    "                if s not in allowed:\n",
    "                    break\n",
    "            else: cnt += 1\n",
    "        return  cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        for i in allowed:\n",
    "            for k in range(len(words)):\n",
    "                words[k] = words[k].replace(i,\"\")\n",
    "                print(words[k],i)\n",
    "\n",
    "        s = 0\n",
    "        for h in words:\n",
    "            if h == \"\":\n",
    "                s = s + 1\n",
    "\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        n=len(words)\n",
    "        count=0\n",
    "        for i in range(n):\n",
    "            if set(words[i]).issubset(set(allowed)):\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        res = 0\n",
    "        for i in words:\n",
    "            tag = True\n",
    "            for j in i:\n",
    "                if j not in allowed:\n",
    "                    tag = False\n",
    "                    break\n",
    "            if tag:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        ans = 0\n",
    "        \n",
    "        for i in words:\n",
    "            a = 0\n",
    "            for x in i:\n",
    "                if x not in allowed:\n",
    "                    a = 1\n",
    "                    break\n",
    "            if a == 0:\n",
    "                ans +=1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        count = 0\n",
    "        for word in words:\n",
    "            word_set = set(word)\n",
    "            if len(word_set) > len(allowed):\n",
    "                continue\n",
    "            else:\n",
    "                cnt = 0\n",
    "                for i in word_set:\n",
    "                    if i not in allowed:\n",
    "                        break\n",
    "                    else:\n",
    "                        cnt += 1\n",
    "                if cnt == len(word_set):\n",
    "                    count += 1\n",
    "        return count\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        return sum(1 for w in words if set(w).issubset(set(allowed)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        result = 0\n",
    "        for i in range(len(words)):\n",
    "            a = list(words[i])\n",
    "            for b in range(len(a)):\n",
    "                if a[b] in allowed:\n",
    "                    if b == len(a) - 1:\n",
    "                        result += 1\n",
    "                    else:\n",
    "                        continue\n",
    "                else:\n",
    "                    break\n",
    "        return result\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        cont = 0\n",
    "        \n",
    "        for i in words:\n",
    "            cont1 = 0\n",
    "            for j in i:\n",
    "                if not j in allowed:\n",
    "                    cont1 = 1\n",
    "                    break\n",
    "                    \n",
    "            if cont1 == 0:\n",
    "                cont += 1\n",
    "        return cont"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "\n",
    "        st = set()\n",
    "        for ch in allowed:\n",
    "            st.add(ch)\n",
    "\n",
    "        ans = 0\n",
    "        for word in words:\n",
    "            flag = True\n",
    "            for ch in word:\n",
    "                if ch not in st:\n",
    "                    flag = False\n",
    "                    break\n",
    "\n",
    "            if flag: ans += 1\n",
    "        \n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        q = len(words)\n",
    "        for i in words:\n",
    "            for j in i:\n",
    "                if j not in allowed:\n",
    "                    q -= 1\n",
    "                    break\n",
    "        return q"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        count=0\n",
    "        for s in words:\n",
    "            flag=1\n",
    "            for i in s:\n",
    "                \n",
    "                if i not in allowed:\n",
    "                    flag=0\n",
    "                    break\n",
    "            if flag==1:\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        s = set(allowed)\n",
    "        ans = 0\n",
    "        for word in words:\n",
    "            temp = True\n",
    "            for i in word:\n",
    "                if i not in s:\n",
    "                    temp = False\n",
    "                    break\n",
    "            ans += 1 if temp else 0\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        allowed=set(allowed)\n",
    "        t=0\n",
    "        for i in words:\n",
    "            c=set(i)\n",
    "            if c&allowed==c:\n",
    "                t+=1\n",
    "        return t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        s = set(allowed)\n",
    "        return sum(all(c in s for c in w) for w in words)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        count = 0\n",
    "        for i in words:\n",
    "            for j in set(i):\n",
    "                if j not in allowed:\n",
    "                    break\n",
    "            else:\n",
    "                count += 1\n",
    "        return count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        mask = 0\n",
    "        for c in allowed:\n",
    "            mask |= 1 << (ord(c) - ord('a'))\n",
    "        res = 0\n",
    "        for word in words:\n",
    "            mask1 = 0\n",
    "            for c in word:\n",
    "                mask1 |= 1 << (ord(c) - ord('a'))\n",
    "            res += (mask1 | mask) == mask\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        mask = 0\n",
    "        for c in allowed:\n",
    "            mask |= 1 << (ord(c) - ord('a'))\n",
    "        res = 0\n",
    "        for word in words:\n",
    "            mask1 = 0\n",
    "            for c in word:\n",
    "                mask1 |= 1 << (ord(c) - ord('a'))\n",
    "            res += (mask1 | mask) == mask\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        total=0\n",
    "        for word in words:\n",
    "           word=word.split()\n",
    "        \n",
    "        for word in words:\n",
    "            for letter in word:\n",
    "                if letter in  allowed:\n",
    "                    flag=True\n",
    "                else:\n",
    "                    flag=False\n",
    "                    break\n",
    "            if flag==True:\n",
    "                total+=1\n",
    "        return total                        \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        return sum(all(c in allowed for c in word) for word in words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        allowedSet = set(allowed)\n",
    "        count = 0\n",
    "        for word in words:\n",
    "            flag = True\n",
    "            for c in word:\n",
    "                if c not in allowedSet:\n",
    "                    flag = False\n",
    "                    break\n",
    "            if flag:\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        count = {}\n",
    "        for i in allowed:\n",
    "            if i not in count:\n",
    "                count[i] = 1\n",
    "        \n",
    "        res = len(words)\n",
    "        for j in words:\n",
    "            for k in j:\n",
    "                if k not in count:\n",
    "                    res -= 1\n",
    "                    break\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        ans = 0 \n",
    "        for word in words :\n",
    "            if len(set(word) - set(allowed)) == 0 :\n",
    "                ans += 1 \n",
    "        return ans "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        s=set(allowed)\n",
    "        return sum(all(c in s for c in w)for w in words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        mask_allowed = 0\n",
    "        for c in allowed:\n",
    "            mask_allowed = mask_allowed | 1 << (ord(c) - ord(\"a\"))\n",
    "        print(bin(mask_allowed)[2:])\n",
    "        # 得到allowed标准的mask\n",
    "        res = 0\n",
    "        for word in words:\n",
    "            mask_word = 0\n",
    "            for c in word:\n",
    "                mask_word = mask_word | 1 << (ord(c) - ord(\"a\"))\n",
    "            # 得到每一个新的word的mask\n",
    "            if (mask_allowed | mask_word) == mask_allowed:\n",
    "                res = res + 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        # allowed，set化\n",
    "        # words, set化\n",
    "        allowset = set(allowed)\n",
    "        res = 0\n",
    "        for word in words:\n",
    "            tmp = set(word)\n",
    "            if len(tmp-allowset) == 0:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        res = 0\n",
    "        for word in words:\n",
    "            for c in word:\n",
    "                if c not in allowed:\n",
    "                    break\n",
    "            else:\n",
    "                res += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        count = 0\n",
    "        for word in words:\n",
    "            word_set = set(word)\n",
    "            cnt = 0\n",
    "            for i in word_set:\n",
    "                if i not in allowed:\n",
    "                    break\n",
    "                else:\n",
    "                    cnt += 1\n",
    "            if cnt == len(word_set):\n",
    "                count += 1\n",
    "        return count\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        allowed=set(allowed)\n",
    "        result=0\n",
    "        for word in words:\n",
    "            if set(word)<=allowed:\n",
    "                result+=1\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        res = 0\n",
    "        for i in words :\n",
    "            for a in i :\n",
    "                if a not in allowed:\n",
    "                    break\n",
    "            else:\n",
    "                    res +=1\n",
    "        return res \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        cnt = 0\n",
    "        s = set(allowed)\n",
    "        for _ in words:\n",
    "            if set(_).issubset(s):\n",
    "                cnt += 1\n",
    "        return cnt\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        mask = 0\n",
    "        for c in allowed:\n",
    "            mask |= 1 << (ord(c) - ord('a'))\n",
    "        res = 0\n",
    "        for word in words:\n",
    "            mask1 = 0\n",
    "            for c in word:\n",
    "                mask1 |= 1 << (ord(c) - ord('a'))\n",
    "            res += (mask1 | mask) == mask\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        res = 0\n",
    "        Set = set(allowed)\n",
    "        #print(Set)\n",
    "        for word in words:\n",
    "            #print(set(word))\n",
    "            if set(word) <= Set:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        a=0\n",
    "        for i in words:\n",
    "            c=0\n",
    "            b=''\n",
    "            i=sorted(list(set(i)))\n",
    "            for j in i:\n",
    "                b+=j\n",
    "            for z in b:\n",
    "                for m in allowed:\n",
    "                    if z==m:\n",
    "                        c+=1\n",
    "                        break\n",
    "            if c==len(b):\n",
    "                a+=1\n",
    "        return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        s = set(allowed)\n",
    "        ans = 0\n",
    "        for word in words:\n",
    "            temp = 0\n",
    "            for i in range(0,len(word)):\n",
    "                if word[i] in s:\n",
    "                    temp += 1\n",
    "                if temp == len(word):\n",
    "                    ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        longest = len(words)\n",
    "        for x in words:\n",
    "            for y in x:\n",
    "                if y not in allowed:\n",
    "                    longest -= 1\n",
    "                    break\n",
    "        return longest"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        s=set(allowed)\n",
    "        ans=0\n",
    "        for w in words:\n",
    "            find=False\n",
    "            for ch in w:\n",
    "                if ch not in s:\n",
    "                    find=True\n",
    "                    break\n",
    "            if not find:\n",
    "                ans+=1\n",
    "        return ans "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        s = set(allowed)\n",
    "        return sum(all(c in s for c in w) for w in words)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        count=0\n",
    "        for word in words:\n",
    "            if all(c in allowed for c in word):\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        def bools(x,y):\n",
    "            for i in range(len(x)):\n",
    "                if x[i] not in y:\n",
    "                    return 0\n",
    "            return 1\n",
    "        count = 0\n",
    "        for i in words:\n",
    "            if bools(i,allowed):\n",
    "                count = count+1\n",
    "        return count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        allowed_set = set(allowed)\n",
    "        count = 0\n",
    "        for word in words:\n",
    "            if all(ch in allowed_set for ch in word):\n",
    "                count += 1\n",
    "        return count\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        c=0\n",
    "        for i in words:\n",
    "            for j in i:\n",
    "                if j not in allowed:\n",
    "                    break\n",
    "            else:\n",
    "                c+=1\n",
    "        return c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        ans=0\n",
    "        allowed=set(allowed)\n",
    "        print(allowed)\n",
    "        for word in words:\n",
    "            for char in word:\n",
    "                if char in allowed:\n",
    "                    continue\n",
    "                break\n",
    "            else:\n",
    "                ans+=1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "from collections import Counter\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        \n",
    "        res = 0\n",
    "        not_found  = False\n",
    "        allowed_ctr = Counter(allowed)\n",
    "        for word in words:\n",
    "            word_ctr = Counter(word)\n",
    "            for k, _ in word_ctr.items():\n",
    "                if k not in allowed_ctr:\n",
    "                    not_found = True\n",
    "                    break\n",
    "            if not not_found:\n",
    "                res += 1\n",
    "            not_found = False\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        return sum([set(word) <= set(allowed) for word in words])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        res = 0\n",
    "        for word in words:\n",
    "            if set(word) - set(allowed) == set():\n",
    "                res+=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        mask = 0\n",
    "        for i in allowed:\n",
    "            mask |= 1 << (ord(i) - ord(\"a\"))\n",
    "        reg = 0\n",
    "        for word in words:\n",
    "            mask1 = 0\n",
    "            for i in word:\n",
    "                mask1 |= 1 << (ord(i) - ord(\"a\"))\n",
    "            reg += (mask1 | mask) == mask\n",
    "        return reg"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        allowed = sum(1 << (ord(i) - ord(\"a\")) for i in allowed)\n",
    "\n",
    "        cnt = 0\n",
    "        for word in words:\n",
    "            cur = 0\n",
    "            for i in word:\n",
    "                cur |= 1 << (ord(i) - ord(\"a\"))\n",
    "            if cur | allowed == allowed:  cnt += 1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        lset = set([c for c in allowed])\n",
    "        ans = 0\n",
    "        for s in words:\n",
    "            f = True\n",
    "            for c in s:\n",
    "                if c not in lset:\n",
    "                    f = False\n",
    "                    break\n",
    "            ans += 1 if f else 0\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        dic = set(allowed)\n",
    "        ans = 0\n",
    "        for word in words:\n",
    "            s = set(word)\n",
    "            d = s | dic\n",
    "            if d == dic:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "\n",
    "        st = set(list(allowed))\n",
    "\n",
    "        ans = 0\n",
    "        for word in words:\n",
    "            flag = True\n",
    "            for ch in word:\n",
    "                if ch not in st:\n",
    "                    flag = False\n",
    "                    break\n",
    "\n",
    "            if flag: ans += 1\n",
    "        \n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        count = 0\n",
    "        for word in words:\n",
    "            word_set = set(word)\n",
    "            if all([i in allowed for i in word_set]):\n",
    "                count += 1\n",
    "        return count\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        count = 0\n",
    "        for i in range(len(words)):\n",
    "            for j in range(len(words[i])):\n",
    "                if words[i][j] not in allowed:\n",
    "                    break\n",
    "            else:\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        res = []\n",
    "        for w in words:\n",
    "            flag = 0\n",
    "            for i in w:\n",
    "                if allowed.find(i)==-1:\n",
    "                    flag =1\n",
    "                    break\n",
    "            if flag==0:\n",
    "                res.append(w)\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        allowed = set(allowed)\n",
    "        result = 0\n",
    "        for word in words:\n",
    "            for sub in word:\n",
    "                if sub not in allowed:\n",
    "                    break\n",
    "            else:\n",
    "                result += 1\n",
    "        return result\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        allow_set = set(allowed)\n",
    "        ans = 0\n",
    "        for word in words:\n",
    "            flag = True\n",
    "            for c in word:\n",
    "                if c not in allow_set:\n",
    "                    flag = False\n",
    "            if flag:\n",
    "                ans += 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        q=0\n",
    "        for i in range(len(words)):\n",
    "            w=1\n",
    "            for j in range(len(words[i])):\n",
    "                if  words[i][j] not in allowed:\n",
    "                    w=0\n",
    "                    break\n",
    "            q+=w\n",
    "        return q\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) :\n",
    "        return sum(set(word)&set(allowed)==set(word) for word in words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        def f(w):\n",
    "            return reduce(or_, (1 << (ord(c) - ord('a')) for c in w))\n",
    "\n",
    "        mask = f(allowed)\n",
    "        return sum((mask | f(w)) == mask for w in words)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        count = 0\n",
    "        allowed_set = set(allowed)\n",
    "        for word in words:\n",
    "            word_set = set(word)\n",
    "            cnt = 0\n",
    "            for i in word_set:\n",
    "                if i not in allowed_set:\n",
    "                    break\n",
    "                else:\n",
    "                    cnt += 1\n",
    "            if cnt == len(word_set):\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        ans=0\n",
    "        for word in words:\n",
    "                if len(set(word)-set(allowed))==0:\n",
    "                    ans+=1\n",
    "        print()\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        count = 0\n",
    "        for word in words:\n",
    "            word_set = set(word)\n",
    "            cnt = 0\n",
    "            for i in word_set:\n",
    "                if i not in allowed:\n",
    "                    break\n",
    "                else:\n",
    "                    cnt += 1\n",
    "            if cnt == len(word_set):\n",
    "                count += 1\n",
    "        return count\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        # '''\n",
    "        # 利用集合判断：把所有字符串转成集合，是allowed子集就+1\n",
    "        # allowed和 word 直接进行子集的比较，需要是同类型\n",
    "        # word 转列表 set()去重，所以 allowed 也要去重\n",
    "        # '''\n",
    "        allowed_list=set(list(allowed))\n",
    "        count=0\n",
    "        for word in words:\n",
    "            word_list=set(list(word))\n",
    "            if allowed_list>=word_list:\n",
    "                count+=1\n",
    "        return count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        count = 0\n",
    "        allowed_set = set(allowed)\n",
    "        for word in words:\n",
    "            word_set = set(word)\n",
    "            cnt = 0\n",
    "            for i in word_set:\n",
    "                if i not in allowed_set:\n",
    "                    break\n",
    "                else:\n",
    "                    cnt += 1\n",
    "            if cnt == len(word_set):\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        cnt = 0\n",
    "        for word in words:\n",
    "            cnt += set(allowed) >= set(word)\n",
    "            # for s in word:\n",
    "            #     if s not in allowed:\n",
    "            #         break\n",
    "            # else: cnt += 1\n",
    "        return  cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        count = 0\n",
    "        for i in words:\n",
    "            if set(allowed) >= set(i):\n",
    "                count += 1\n",
    "\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        n = len(words)\n",
    "        a = 0\n",
    "        for i in range(n):\n",
    "            b = True\n",
    "            for s in words[i]:\n",
    "                \n",
    "                if s not in allowed:\n",
    "                    b = False\n",
    "                    break\n",
    "            if (b==True):\n",
    "                a += 1\n",
    "        return a\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        ans = 0\n",
    "        for word in words:\n",
    "            flag = 0\n",
    "            for le in word:\n",
    "                if flag :\n",
    "                    break\n",
    "                if le not in allowed:\n",
    "                    flag = 1\n",
    "            if not flag:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        count = 0\n",
    "        for word in words:\n",
    "            if len(set(word)) > len(allowed):\n",
    "                continue\n",
    "            else:\n",
    "                cnt = 0\n",
    "                word_set = set(word)\n",
    "                for i in word_set:\n",
    "                    if i not in allowed:\n",
    "                        break\n",
    "                    else:\n",
    "                        cnt += 1\n",
    "                if cnt == len(word_set):\n",
    "                    count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countConsistentStrings(self, allowed: str, words: List[str]) -> int:\n",
    "        cnt = 0\n",
    "        for word in words:\n",
    "            i = 0\n",
    "            for c in word:\n",
    "                if c not in allowed:\n",
    "                    break\n",
    "                i += 1\n",
    "            if i == len(word):\n",
    "                cnt += 1\n",
    "        return cnt"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
